package com.remote.server.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.smartcar.common.result.PageResult;
import com.smartcar.common.result.Result;
import com.remote.common.Equipment;
import com.remote.server.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 设备黑名单
 */

@RestController
@RequestMapping("/equipment")
public class EquipmentController {
    @Autowired
    private EquipmentService equipmentService;

    /**
     * 设备黑名单列表
     * @param equipment
     * @return
     */

    @PostMapping("/equipmentList")
    public Result<PageResult<Equipment>> equipmentList(Equipment equipment){
        PageHelper.startPage(equipment.getPageNum(),equipment.getPageSize());
        List<Equipment> list = equipmentService.equipmentList(equipment);
        PageInfo<Equipment> pageInfo = new PageInfo<>(list);
        return PageResult.toResult(pageInfo.getTotal(),list);
    }

    /**
     * 加入黑名单
     * @param equipment
     * @return
     */

    @PostMapping("/locksDevice")
    public Result LocksDevice(@RequestBody Equipment equipment){
        equipmentService.LocksDevice(equipment);
        return Result.success();
    }



}
